{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="test-table-reload-btn">
                <div class="layui-inline">
                    <select name="seoid" id="seoid" lay-filter="seoid">
                        <option value="">选择优化师</option>
                        {volist name="seo" id="vo" }
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="keywords" id="keywords" autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>


        </div>
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList" ></table>
            <script type="text/html" id="toolbarDemo">
            </script>
            <script type="text/html" id="op">
                <a class="layui-btn layui-btn-xs " lay-tips="查看网站信息" lay-event="show_webinfo" >网站信息</a>
                <a class="layui-btn layui-btn-xs"  lay-tips="查看‘{{d.urlName}}’关键词列表" lay-text="‘{{d.urlName}}’关键词列表" lay-href="{:url(('/admin/web_key/index'))}?webID={{d.id}}">关键词</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-tips="释放优化师" lay-event="reset_seo">释放</a>
            </script>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util','form'], function () {

        //表格
        var $ = layui.$,form = layui.form,layer = layui.layer,table = layui.table;
        table.render({
            elem: '#tbList',
            url: "{:url('getList')}",
            where: {type:'zc'},
            toolbar: '#toolbarDemo',
            cellMinWidth: 80,
            cols: [[
                {field: 'id', fixed: 'left', title: 'ID'},
                {field: 'urlName',fixed: 'left',title: '网站名'},
                {field: 'url',fixed: 'left',title: '网址'},
                {field: 'keyNum',  title: '关键词数量',sort:true},
                {field: 'seo_name',  title: '优化师',sort:true},
                {field: 'gotime', title: '分配时间'},
                {fixed: 'right', title: '操作',width:250, toolbar: '#op'}
            ]],
            page: true,
            limit:15
        });

        // 监听工具条
        table.on('tool(tbList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'show_webinfo') {
                var url = "{:url(('/admin/web/info'))}?id=" + data['id'];
                var index = layer.open({
                    type: 2,
                    title: '网站展示',
                    area: ['90%', '90%'],
                    shade: 0,
                    maxmin: true,
                    content: url,
                    zIndex: layer.zIndex
                });
            }else if(obj.event === 'reset_seo') {
                layer.confirm('确定释放优化师？', {icon: 3, title: '提示'}, function (index) {
                    $.post("{:url(('/admin/web/reset_seo'))}", {id: data['id']}, function (result) {
                        if (result['code'] == 0) {
                            layer.msg(result['msg'], {icon: 1, time: 2000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(result['msg'], {icon: 3, time: 3000});
                        }
                    });
                });
            }
        });
        //监听单元格编辑
        table.on('edit(tbList)', function (obj) {
            var value = obj.value; //得到修改后的值
            var data = obj.data; //得到所在行所有键值
            var field = obj.field; //得到字段
            layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);

            $.post("{:url('edit')}", {id: data.id, content: value}, function (result) {
                if (result['code'] == 0) {
                    layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(result['msg'], {icon: 3, time: 3000});
                }
            });
        });


        //操作
        var $ = layui.$, active = {
            reload: function(){
                var seoID=$('#seoid').val();
                var keywords=$('#keywords').val();

                //执行重载
                table.reload('tbList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        seoid: seoID
                        ,keywords: keywords
                    }
                });

            }
        };

        // $("#btnAdd").on('click', function () {
        //     var type = $(this).data('type');
        //     active[type] ? active[type].call(this) : '';
        // });

        $('.test-table-reload-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
{/block}